const db = require("../lib/db");
function articleList(){
    return new Promise((resolve,reject)=>{
        let sql = "select * from article";
        db.querySql(sql).then(data=>{
            if(data.length==0){
                resolve(3003)
            }else{
                //对数组做乱序处理
                let err = data.sort(()=>0.5 - Math.random());
                let err2 = []
                err.map(element=>{
                    err2.push({
                        _id:element._id,
                        title:element.title,
                        desc:element.article_desc,
                        author:element.author,
                        authorId:element.authorId,
                        classify:element.classify,
                        content:element.content
                    })
                })
                resolve(err2)
            }
        })
}
    )}
    module.exports = articleList